package com.iocoder.yudao.module.erp.service.stock;


import cn.iocoder.yudao.framework.common.pojo.PageResult;
import com.iocoder.yudao.module.erp.controller.admin.stock.vo.stock.ErpProductStockPageVo;
import com.iocoder.yudao.module.erp.mapper.stock.ErpProductStockMapper;
import com.iocoder.yudao.module.erp.model.stock.ErpStockDO;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal;

@Service
public class ErpProductStockServiceImpl  implements ErpProductStockService{

    @Resource
    private ErpProductStockMapper erpProductStockMapper;


    @Override
    public PageResult<ErpStockDO> getProductStockPage(ErpProductStockPageVo pageReqVO) {

        return erpProductStockMapper.selectPage(pageReqVO);
    }


    @Override
    public ErpStockDO getStock(Long id) {
        return erpProductStockMapper.selectById(id);
    }

    @Override
    public ErpStockDO getStock(Long productId, Long warehouseId) {
        return erpProductStockMapper.selectByProductIdAndWarehouseId(productId, warehouseId);
    }


    @Override
    public BigDecimal getStockCount(Long productId) {
        BigDecimal count = erpProductStockMapper.selectSumByProductId(productId);
        return count != null ? count : BigDecimal.ZERO;
    }

    @Override
    public PageResult<ErpStockDO> getStockPage(ErpProductStockPageVo pageReqVO) {
        return erpProductStockMapper.selectPage(pageReqVO);
    }
}
